<script id="tpl" type="text/html">
    <div class="row" style="margin-left:0;margin-right:0;">
        <div class="oneRow">
            <div class="col-xs-5">
                <div class="input-group" style="margin:4px 0;">
                    <span class="input-group-addon">订购数量</span>
                    <input type="text" class="form-control number">
                </div>
            </div>
            <div class="col-xs-7">
                <div class="input-group" style="margin:4px 0;">
                    <span class="input-group-addon">享受价格</span>
                    <input type="text" class="form-control price">
                    <span class="input-group-btn">
                <button class="btn btn-info" onclick="addPriceRow()" type="button">+</button>
                </span>
                    <span class="input-group-btn">
                <button class="btn btn-danger" onclick="delPriceRow(this)" type="button">-</button>
                </span>
                </div>
            </div>
        </div>
    </div>
</script>

<div class="row" style="margin-left:0;margin-right:0;">
    <div class="oneRow">
        <div class="col-xs-5">
            <div class="input-group" style="margin:4px 0;">
                <span class="input-group-addon">订购数量</span>
                <input type="text" class="form-control number">
            </div>
        </div>
        <div class="col-xs-7">
            <div class="input-group" style="margin:4px 0;">
                <span class="input-group-addon">享受价格</span>
                <input type="text" class="form-control price">
                <span class="input-group-btn">
                <button class="btn btn-info" onclick="addPriceRow()" type="button">+</button>
                </span>
            </div>
        </div>
    </div>
</div>

<div class="row" id="rowList" style="margin-left:0;margin-right:0;"></div>
<script>
    //添加行
    function addPriceRow() {
        $('#rowList').append(template('tpl'));
    }
    //删除行
    function delPriceRow(obj) {
        var length = $('.oneRow').length
        if(length>1){
            $(obj).closest('.oneRow').remove();
        }
    }
    //获取数据
    function getLadderPrice() {
        var result = [];
        $('.oneRow').each(function(){
            var number =$(this).find('.number').val();
            var price =$(this).find('.price').val();
            if(number=='' || price==''){
                result = [];
                alert('请填写完整订购数量和价格！');
                return false;
            }else{
                result.push(number+':'+price);
            }
        })
        return result.join(',');
    }
</script>